<!doctype html>
<html>
    <head>
        <!-- meta -->
        <!-- meta -->
        <title>API</title>
        <!-- css -->
        <link href="../styles/examples.css" rel="stylesheet"/>
        <link href="../../source/styles/kendo.common.css" rel="stylesheet"/>
        <link href="../../source/styles/kendo.kendo.css" rel="stylesheet"/>
        <!-- css -->
        <!-- script -->
        <script src="../js/jquery.js"></script>
        <script src="../../source/js/kendo.core.js"></script>
        <script src="../../source/js/kendo.draganddrop.js"></script>
        <script src="../../source/js/kendo.slider.js"></script>
        <!-- script -->
    </head>
    <body>
        <!-- nav -->
        <!-- nav -->
        <!-- description -->
        <!-- description -->
        <div id="example" class="k-content">

            <div class="configuration" style="width: 240px;">
                <span class="configHead">Configuration</span>
                <span class="configTitle">Slider API Functions</span>
                <ul class="options">
                    <li>
                        <input type="number" min="0" max="10" id="newValue" value="1" />
                        <button class="k-button" id="setSliderValue">Set value</button>
                    </li>
                    <li>
                        <button class="k-button" id="getSliderValue">Get value</button>
                    </li>
                    <li>
                        <button class="k-button" id="enableSlider">Enable</button> or <button class="k-button" id="disableSlider">Disable</button>
                    </li>
                </ul>
                <span class="configTitle">RangeSlider API Functions</span>
                <ul class="options">
                    <li>
                        <input type="number" min="0" max="10" id="startValue" value="1" />
                        <button class="k-button" id="setStartValue">Set selection start</button>
                    </li>
                    <li>
                        <input type="number" min="0" max="10" id="endValue" value="1" />
                        <button class="k-button" id="setEndValue">Set selection end</button>
                    </li>
                    <li>
                        <button class="k-button" id="getRangeSliderValue">Get value</button>
                    </li>
                    <li>
                        <button class="k-button" id="enableRangeSlider">Enable</button>
                    </li>
                    <li>
                        <button class="k-button" id="disableRangeSlider">Disable</button>
                    </li>
                </ul>
            </div>

            <div>
                <input type="range" id="slider" />
            </div>

            <div id="rangeslider" style="margin-top: 40px;">
                <input type="range" />
                <input type="range" />
            </div>

            <script>
                $(document).ready(function() {
                    var slider = $("#slider").kendoSlider().data("kendoSlider"),
                        rangeSlider = $("#rangeslider").kendoRangeSlider().data("kendoRangeSlider"),
                        setValue = function(e) {
                            if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                                var value = parseInt($("#newValue").val(), 10);

                                if (isNaN(value) || value < 0 || value > 10) {
                                    alert("Value must be a number between 0 and 10");
                                    return;
                                }

                                slider.value(value);
                            }
                        },
                        setStartValue = function(e) {
                            if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                                var startValue = parseInt($("#startValue").val(), 10);

                                if (isNaN(startValue) || startValue < 0 || startValue > 10) {
                                    alert("Value must be a number between 0 and 10");
                                    return;
                                }

                                var endValue = getValues()[1];
                                rangeSlider.values(startValue, endValue);
                            }
                        },
                        setEndValue = function(e) {
                            if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                                var startValue = getValues()[0];
                                var endValue = parseInt($("#endValue").val(), 10);

                                if (isNaN(endValue) || endValue < 0 || endValue > 10) {
                                    alert("Value must be a number between 0 and 10");
                                    return;
                                }

                                rangeSlider.values(startValue, endValue);
                            }
                        };

                    $("#getSliderValue").click(function() {
                        alert(slider.value());
                    });

                    $("#enableSlider").click(function() {
                        slider.enable();
                    });

                    $("#disableSlider").click(function() {
                        slider.disable();
                    });

                    function getValues() {
                        return rangeSlider.values();
                    }

                    $("#setSliderValue").click(setValue);
                    $("#newValue").keypress(setValue);

                    $("#setStartValue").click(setStartValue);
                    $("#startValue").keypress(setStartValue);

                    $("#setEndValue").click(setEndValue);
                    $("#endValue").keypress(setEndValue);

                    $("#getRangeSliderValue").click(function() {
                        alert(getValues());
                    });

                    $("#enableRangeSlider").click(function() {
                        rangeSlider.enable();
                    });

                    $("#disableRangeSlider").click(function() {
                        rangeSlider.disable();
                    });
                });
            </script>
        </div>
        <!-- tools -->
        <!-- tools -->
    </body>
</html>
